from dataclasses import dataclass

from flask import Flask, Blueprint
from injector import inject

from internal.handler import (
    AppHandler,
    BuiltinProviderManagerHanlder,
    APIToolsHanlder,
    UploadFileHandler,
    DatasetHandler
)


@inject
@dataclass
class Router:
    handler: AppHandler
    api_tools_hanlder: APIToolsHanlder
    tools_handler: BuiltinProviderManagerHanlder
    upload_file_handler: UploadFileHandler
    dataset_handler: DatasetHandler

    # get_tool_provider_find_name
    def reg_router(self, app: Flask):
        bp = Blueprint("llmops", __name__, url_prefix="")
        bp.add_url_rule("/ping", view_func=self.handler.pings)
        bp.add_url_rule("/chat", methods=["post"], view_func=self.handler.chart)
        bp.add_url_rule("/addData", methods=["post"], view_func=self.handler.addData)
        bp.add_url_rule("/delData/<uuid:id>", view_func=self.handler.delData)
        bp.add_url_rule("/getProviders", view_func=self.tools_handler.get_tool_provider_all)
        bp.add_url_rule("/findProviderTool/<string:provider_name>/tools/<string:tool_name>",
                        view_func=self.tools_handler.get_tool_provider_find_name)
        bp.add_url_rule("/getProviderIcon/<string:provider_name>",
                        view_func=self.tools_handler.get_provider_icon)
        bp.add_url_rule("/getCategory", view_func=self.tools_handler.get_category)
        bp.add_url_rule("/updateData/<uuid:id>", methods=["post"], view_func=self.handler.updateData)
        bp.add_url_rule("/apiTools/validatorSchema", methods=["post"],
                        view_func=self.api_tools_hanlder.validator_schema)
        bp.add_url_rule("/tools/create_api_tools", methods=["post"], view_func=self.api_tools_hanlder.create_api_tools)
        bp.add_url_rule("/tools/getToolProvider/<uuid:provider_id>", view_func=self.api_tools_hanlder.get_tool_provider)
        bp.add_url_rule("/tools/getTool/<uuid:provider_id>/tools/<string:tool_name>",
                        view_func=self.api_tools_hanlder.get_tool)
        bp.add_url_rule("/tools/deleteToolProvider/<uuid:provider_id>",
                        view_func=self.api_tools_hanlder.delete_tool_provider)
        bp.add_url_rule("/tools/getProviderList",
                        view_func=self.api_tools_hanlder.get_api_tool_providers_with_page)
        bp.add_url_rule("/tools/update_tool_provider/<uuid:provider_id>", methods=["post"],
                        view_func=self.api_tools_hanlder.update_tool_provider)
        bp.add_url_rule("/upload", methods=["post"], view_func=self.upload_file_handler.upload_file)
        bp.add_url_rule("/upload_img", methods=["post"], view_func=self.upload_file_handler.upload_img)
        bp.add_url_rule("/dataset/createDataSet", methods=["post"], view_func=self.dataset_handler.create_dateset)
        bp.add_url_rule("/dataset/getDatasetItem/<uuid:dataset_id>", view_func=self.dataset_handler.get_dataset)
        bp.add_url_rule("/dataset/updateDataset/<uuid:dataset_id>",
                        methods=["post"],
                        view_func=self.dataset_handler.update_dataset)
        bp.add_url_rule("/dataset/getDataSetList", view_func=self.dataset_handler.get_dataset_with_page)
        app.register_blueprint(bp)
